class WeaponNewListUI extends eui.ItemRenderer{
    private main_group:eui.Group;
    private oldData:any;
    private count:number = 100;
    private lastItem:WeaponSmallItem;
    constructor()
    {
        super();
        this.skinName = 'WeaponNewListView';
    }

    public childrenCreated()
    {
        super.childrenCreated();
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.clear, this);
    }

    public dataChanged()
    {
        if(!this.data || this.data == this.oldData)return;
        this.oldData = this.data;
        this.updateUI();
    }

    public get da()
    {
        return this.oldData;
    }


    protected updateUI()
    {
        let list = this.data.good_list.split(',');
        for(let index = 0;index<6;index++)
        {
            let item:WeaponSmallItem = this.main_group.getChildByName('item_'+(index+1)) as WeaponSmallItem;
            if(list[index])
            {
                let id = parseInt(list[index]);
                let v = WeaponTpl.instance().getDataByWeaponId(id);
                let clone = JSON.parse(JSON.stringify(v));
                let i = index;
                if(i == 0 && this.itemIndex == 0)
                    clone.index = 1;
                else
                    clone.index = null;
                if(!item)
                {
                    item = new WeaponSmallItem();
                    item.anchorOffsetX = item.width >> 1;
                    item.anchorOffsetY = item.height >> 1;
                    item.name = 'item_'+(i+1);
                    this.main_group.addChild(item);
                }
                item.x = item.anchorOffsetX + 149 * (i % 3);
                item.y =  item.anchorOffsetY + Math.floor((i / 3)) * 143;
                item.show(clone);
                item.visible = true;
            }
            else
            {
                let item = this.main_group.getChildByName('item_'+(index+1));         
                if(item)
                {
                    item.visible = false;
                }
            }
        }
    }

    public clear()
    {
        this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.clear, this);
        this.oldData = null;
    }
}